#ifndef __SIP__CORE__HEADER__
#define __SIP__CORE__HEADER__

#include "paramconfig.h"
#include "common.h"
#include <memory> // export std::auto_ptr

class SipCore
{
public:
    SipCore(const ConfigParam& param);
    virtual ~SipCore();
    virtual bool init();
    virtual void uninit();
    ConfigParam& param() { return mParam; }
    const ConfigParam& param() const { return mParam; }

    void poll_sip_event(int tv_s, int tv_ms);

protected:
    virtual void proc_register_response(const eXosip_event* const osipEvt) = 0;
    virtual void proc_call_request(const eXosip_event* const osipEvt) = 0;
    virtual void proc_call_response(const eXosip_event* const osipEvt) = 0;
    virtual void proc_call_ack(const eXosip_event* const osipEvt) = 0;
    virtual void proc_call_cancel(const eXosip_event* const osipEvt) = 0;
    virtual void proc_call_message_request(const eXosip_event* const osipEvt) = 0;
    virtual void proc_call_message_response(const eXosip_event* const osipEvt) = 0;
    virtual void proc_call_close(const eXosip_event* const osipEvt) = 0;
    virtual void proc_call_release(const eXosip_event* const osipEvt) = 0;
    virtual void proc_new_message(const eXosip_event* const osipEvt) = 0;
    virtual void proc_message_response(const eXosip_event* const osipEvt) = 0;

    class SipLogHandler
    {
    public:
        SipLogHandler(const std::string& filepath);
        ~SipLogHandler();
        void log_rotate(const std::string& newFileName);
        bool valid() const;
        operator FILE*() const;
    protected:
        std::string mFileDir;
        std::string mFilePathName;
        FILE*   mHandler;
    };
    std::auto_ptr<SipLogHandler>    mLogHandler;
    ConfigParam                     mParam;
    eXosip_t*                       mSipCtx;
};

#endif // #ifndef __SIP__CORE__HEADER__

